package com.kuang.bascic.controller;

import com.kuang.bascic.utils.AjaxResult;
import com.kuang.bascic.utils.FastDfsUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
@RequestMapping("/fastdfs")
public class FastDfsController {
    @PostMapping ("/uplode")
    public AjaxResult Uplode(MultipartFile file){
        // 可使用@Requestpart 注解@Requestpart（value=file,requred=true）
        try {
            String originalFilename = file.getOriginalFilename();// 获取文件的源文件名字
            // 获取文件后缀 有api获取
            byte[] originalFilenameBytes = originalFilename.getBytes();
            String exname = originalFilename.substring(originalFilename.indexOf(".") + 1);
            // 返回一个路径
            String path = FastDfsUtil.upload(originalFilenameBytes, exname);
            System.out.println(path);
            return AjaxResult.me().setResultObj(path);
        } catch (Exception e) {
           return AjaxResult.me().setMessage(e.getMessage());
        }
    }
}
